<?php
class Comentario extends AppModel {

	var $name = 'Comentario';
        var $recursive = 2;
	var $validate = array(
		'texto_id' => array('notempty'),
		'nome' => array('notempty'),
		'email' => array('email'),
		'site' => array('rule'=>'url','allowEmpty'=>true)
	);
        var $order = 'Comentario.created DESC';

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Texto' => array(
			'className' => 'Texto',
			'foreignKey' => 'texto_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

        function validateCaptcha($fieldName, $params){
            $caseInsensitive = true;

            $val = $this->data[$this->name]['captcha'];

            if ($caseInsensitive) {
                $val = strtoupper($val);
            }

            //php-captcha.inc.php
            if(!defined('CAPTCHA_SESSION_ID'))
                define('CAPTCHA_SESSION_ID', 'php_captcha');

             if (!empty($_SESSION[CAPTCHA_SESSION_ID]) && $val == $_SESSION[CAPTCHA_SESSION_ID]) {
                // clear to prevent re-use
                unset($_SESSION[CAPTCHA_SESSION_ID]);

                return true;
             }

             return false;
        }
}
?>